'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }
  async addRedo(){
    const { ctx } = this;
    let {name,tel,addressDetail}=ctx.request.body.content
    let address =addressDetail
    let obj={
      name,tel,address
    }
    let awit=await this.app.mysql.insert('dz',{
      name:obj.name,address:obj.address,tel:obj.tel
    })
  ctx.body={
    code:"FLG",
    msg:awit,
    mats:200
  }
  }
  async getaddrom(){
    const {ctx}=this;
    let {id}=ctx.request.body
    console.log(id)
    let awit =await this.app.mysql.get('dz',{id})
  
    ctx.body = {
      code:"FLG",
      msg:awit,
      mats:200
    };
  }
  async detali(){
    const {ctx}=this;
    let {id}=ctx.request.body
    let awit =await this.app.mysql.delete('dz',{id})
    ctx.body = {
      code:"FLG",
      msg:awit,
      mats:200
    };
  }
  async getList() {
    const { ctx } = this;

    let awit=await this.app.mysql.select('zhn')
    console.log(awit)
    ctx.body = {
      code:"FLG",
      msg:awit,
      mats:200
    };
  }
  async getDz(){
    const {ctx}=this;
    let awit =await this.app.mysql.select("dz")
   ctx.body={
     code:"FLG",
     msg:awit,
     mats:200
   }
  }
  async login() {
    const { ctx } = this;
  let {user}=ctx.request.body
  console.log(user)
    let awit=await this.app.mysql.get('zhn',{user})
    console.log(awit)
  if(awit){  
    ctx.body = {
      code:"FLG",
      msg:awit,
      mats:200
    };
  }else{
    ctx.body = {
      code:"SCSS",
      msg:awit,
      mats:400
    };
  }
  }
}

module.exports = HomeController;
